<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/4/26
 * Time: 16:34
 */

namespace app\common\service;

//站点信息
class IpsWebsiteProtect
{
    /**
     * @name 列表
     * @param $params
     * @param $limit
     * @return mixed
     * @Author wx
     * @date 2019/8/14 16:35
     */
    function list($hostId, $params, $limit)
    {
        $db = db('ips_website_protect')->where('host_id',$hostId);

        $db = $this->condition($db, $params);

        $list = $db->order('id desc')->paginate($limit)->toArray();

        return $list;
    }

    /**
     * @name 条件查询
     * @param $db
     * @param $params
     * @return mixed
     * @Author wx
     * @date 2019/8/14 16:35
     */
    function condition($db, $params)
    {
        if (isset($params['domain_name']) && !empty($params['domain_name'])) {
            $db->where('domain_name', $params['domain_name']);
        }
        if (isset($params['descirption']) && !empty($params['descirption'])) {
            $db->where('descirption', 'like', '%'.$params['descirption'].'%');
        }
        if (isset($params['website_path']) && !empty($params['website_path'])) {
            $db->where('website_path', 'like', '%'.$params['website_path'].'%');
        }
        if (isset($params['file_protect']) && is_numeric($params['file_protect'])) {
            $db->where('file_protect', $params['file_protect']);
        }
        if (isset($params['create']) && is_numeric($params['create'])) {
            $db->where('create', $params['create']);
        }
        if (isset($params['modify']) && is_numeric($params['modify'])) {
            $db->where('modify', $params['modify']);
        }
        if (isset($params['del']) && is_numeric($params['del'])) {
            $db->where('del', $params['del']);
        }
        if (isset($params['status']) && is_numeric($params['status'])) {
            $db->where('status', $params['status']);
        }

        return $db;
    }

    function data()
    {
        return db('ips_website_protect')->field('id,domain_name')->select();
    }

    /**
     * @name 添加
     * @param $data
     * @return int|string
     * @author wx
     * @date 2019/9/2 10:57
     */
    function add($data)
    {
        return db('ips_website_protect')->insert($data);
    }

    /** 删除
     * @name
     * @param $condition
     * @return int
     * @author wx
     * @date time
     */
    function del($condition)
    {
        return db('ips_website_protect')->where($condition)->delete();
    }

    /**
     * @name 查询数据
     * @param $condition
     * @param string $field
     * @return array|null|\PDOStatement|string|\think\Model
     * @author wx
     * @date 2019/9/2 10:56
     */
    function findData($condition, $field = '*')
    {
        return db('ips_website_protect')->field($field)->where($condition)->find();
    }

    /**
     * @name 编辑数据
     * @param $condition
     * @param $update
     * @return int|string
     * @author wx
     * @date 2019/9/2 10:56
     */
    function modify($condition, $update)
    {
        return db('ips_website_protect')->where($condition)->update($update);
    }

    /**
     * @name: 需要保护的文件范围
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2019-09-26 14:42:55
     */
    function havProtect($hostId)
    {
        $return = db('ips_website_protect')->where('host_id', $hostId)->where('status',1)->count();

        return $return;
    }


}